<?php
session_start();
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session

// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
	case 'add':
		if ($cart) {
			$cart .= ','.$_GET['id'];
		} else {
			$cart = $_GET['id'];
		}
		break;
	case 'delete':
		if ($cart) {
			$items = explode(',',$cart);
			$newcart = '';
			foreach ($items as $item) {
				if ($_GET['id'] != $item) {
					if ($newcart != '') {
						$newcart .= ','.$item;
					} else {
						$newcart = $item;
					}
				}
			}
			$cart = $newcart;
		}
		break;
	case 'update':
	if ($cart) {
		$newcart = '';
		foreach ($_POST as $key=>$value) {
			if (stristr($key,'qty')) {
				$id = str_replace('qty','',$key);
				$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
				$newcart = '';
				foreach ($items as $item) {
					if ($id != $item) {
						if ($newcart != '') {
							$newcart .= ','.$item;
						} else {
							$newcart = $item;
						}
					}
				}
				for ($i=1;$i<=$value;$i++) {
					if ($newcart != '') {
						$newcart .= ','.$id;
					} else {
						$newcart = $id;
					}
				}
			}
		}
	}
	$cart = $newcart;
	break;
}
$_SESSION['cart'] = $cart;
?>
<?php include("header.php")?>
                
				
				
                <div id="content">
                      <div class="slider-wrapper theme-default">
                            <div class="ribbon"></div>
                            <div id="slider" class="nivoSlider">
                                <img src="images/banner/b1.jpg" alt="" />
                                <a href="http://dev7studios.com"><img src="images/banner/b3.jpg" alt="" title="This is an example of a caption" /></a>
                                <img src="images/banner/b2.jpg" alt="" data-transition="slideInLeft" />
                                <img src="images/banner/b4.jpg" alt="" title="#htmlcaption" />
                            </div>
                            <div id="htmlcaption" class="nivo-html-caption">
                                <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
                            </div>
                        </div>
                        <script type="text/javascript" src="js/jquery.nivo.slider.pack.js"></script>
                        <script type="text/javascript">
                        $(window).load(function() {
                            $('#slider').nivoSlider();
                        });
                        </script>
                    <div id="primary">
                    <h1>Giỏ hàng của bạn</h1>
                        <div id="shoppingcart">
                        <?php
                        echo writeShoppingCart();
                        ?>
                        </div>
                        
                        <div id="contents">
                        <?php
                        echo showCart();
                        ?>
                        </div>
                        	<link rel="js/general.css" type="text/css" media="screen">

                        <div id="main-meta">
						
				<?php
				  echo $name_sp;
				
				?>
				
<style>
  .error{
   color:red;
  }
</style>

<?php
 if(isset($_POST['thanhtoan'])){
						$name=$_POST['name'];
						$phone=$_POST['phone'];
						$email=$_POST['email'];
						$message=$_POST['message'];
						$mydate=$_POST['mydate'];
						$phuongtien=$_POST['phuongtien'];
						 
						 
						
					    $sql="INSERT INTO DELIVERY VALUES('','$name', '$phone','$email', '$message', '$mydate','$phuongtien')";
						 $mysql->query($sql);
                          
                        
                     }?>

        				  <form action="payment.php" method="POST" id="customForm">
                            <div>
                                <label>Tên khách hàng:</label>
                               	<input class="error" id="name" name="name" type="text"/>
			                	<span class="error" id="nameInfo">Tên bạn phải lớn hơn 3 kí tự</span>   
                             </div>
                            
                            <div>
                                <label>Số điện thoai:</label>
                                	<input class="error" id="phone" name="phone" type="text"/>
			                	<span class="error" id="phoneInfo">Số điện thoại 10 số</span>   
                        
                             </div>
                            
                            	<div>
                				<label for="email">E-mail</label>
                				<input class="error" id="email" name="email" type="text"/>
                				<span class="error" id="emailInfo">Email hợp lệ</span>
                			</div>
                             
                            <div>
                				<label for="message">Địa chỉ giao hàng</label>
                				<textarea id="message" name="message" cols="" rows=""></textarea>
                			</div>
                            
             
                             
                            <div>
                                <label>Ngày giao hàng:</label>
                                <input type="text" id="mydate" gldp-id="mydate" name="mydate" />
                                <div gldp-el="mydate"
                                     style="width:400px; height:300px; position:absolute; top:70px; left:100px;">
                                </div>
                             </div>
                             
                             <div>
                               <label>Phương tiện:</label>
                               <select name="phuongtien">
                                  <option value="oto">Xe máy</option>
                                   <option value="oto">Ô tô</option>
                                    <option value="oto">Máy bay</option>
                                    
                               </select>
                               </div>
                              <input type="submit" value="Thanh toán" name="thanhtoan" id="thanhtoan" />
                               
                             
                             
                             
                            </form>
                            
                        </div><!--end #main-meta-->
                  	  
                        	<script type="text/javascript" src="js/validation.js"></script>

                  
                  </div><!--end #primary-->
                  
                  
                  
                  <?php include("sidebar.php");?>
                  
                  <div class="clear"></div>     
                </div><!--end #conttent-->
    <?php include("footer.php")?>